package fr.neticar.webremoteclient.server.application;

import java.awt.Component;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import javax.swing.KeyStroke;

import fr.neticar.webremoteclient.client.ImagePropertyBean;
import fr.neticar.webremoteclient.client.exception.WRCException;
import fr.neticar.webremoteclient.server.ImageContentBean;
import fr.neticar.webremoteclient.server.ImageManager;
import fr.neticar.webremoteclient.server.rdp.Rdesktop;
import fr.neticar.webremoteclient.server.rdp.RdesktopCanvas;

public class RDPClient implements IRemoteClient {

	private Rdesktop rdp;

	private ImageManager imageManager;
	
	private String host;
	private String port;
	private String password;

	public RDPClient(String host, String port, String password)
			throws WRCException {
		imageManager = new ImageManager();
		rdp = new Rdesktop(host, null, null, null, imageManager);

	}

	@Override
	public boolean containsNewImage() {

		return imageManager.containsImage();
	}

	@Override
	public Component getEventSourceComponent() {

		return rdp.getWindow().getCanvas();
	}

	@Override
	public ImageContentBean getNextImage(String id) {
		return imageManager.getImage(id);
	}

	@Override
	public ImagePropertyBean getNextImageProperty() {
		return imageManager.getFirstBean();
	}

	@Override
	public int getScreenHeight() {

		return (int) rdp.getScreenSize().getHeight();
	}

	@Override
	public int getScreenWidth() {

		return (int) rdp.getScreenSize().getWidth();
	}

	@Override
	public void sendKeyEvent(KeyEvent ke) {
		
		RdesktopCanvas rdpCanvas = rdp.getWindow().getCanvas();
		rdpCanvas.fireKeyEvent(ke);
//		RdesktopCanvas rdpCanvas = rdp.getWindow().getCanvas();
//		KeyStroke ks = KeyStroke.getKeyStroke(ke.getKeyChar());
//		ke.setKeyCode(ks.getKeyCode());
//		rdpCanvas.processKeyEventFromWRC(ke);

	}

	@Override
	public void sendMouseEvent(MouseEvent e, boolean mouseMove) {
		RdesktopCanvas rdpCanvas = rdp.getWindow().getCanvas();
		rdpCanvas.processMouseEventFromWRC(e);

	}

	@Override
	public void stop() {
		rdp.getCommun().exit();

	}


		
		


}
